<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="ID"
        width="80">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="100">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="150">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="250">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
    </el-table>

    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="goPage"
      align="right">
    </el-pagination>
  </div>
</template>

<script>

// 引入axios
// import axios from "axios";

export default {
  name: 'user',
  data () {
    return {
      tableData: [],
      total:0,
      pageSize:5,
      currentPage:1,
    }
  },
  methods:{
    goPage(currentPage){
      // 1.当用户选择了页码，说明页码发生了丐帮，这是currentPage的值就是用户选择的页码值
      this.currentPage = currentPage;
      // 2.改变了页码就要发起请求获取指定页码数据，所以需要Axios请求，我们可以将发起骑牛的代码封装成函数方法，直接调用即可
      this.list();
    },
    list(){
      // 根据Mock接口路径，以及需要的两个参数，发送请求
      this.$http.post("https://www.fastmock.site/mock/f3fc709d34e6e935b2ff562faaa77c35/pethome/department/findDepartments",
        {"currentPate":this.currentPage, "pageSize":this.pageSize}).then(result => {
          this.tableData = result.data.data;
          this.total = result.data.totals;
      }).catch(error => {
        console.log(error)
      })
    }
  },
  mounted() {// 钩子函数 在页面初始化完成后执行
    this.list();
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
